"""
对于多个类，且一个类依赖于另一个类，需要先设计被依赖的类
eg:房子、家具
   先设计家具
"""


class Furniture(object):
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return f"{self.name} 占地 {self.area}"


class House(object):
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area  # 剩余空间
        self.items_list = []  # 家具列表

    def __str__(self):
        return f"{self.house_type}，总面积{self.area},可用面积{self.free_area},家具有：{self.items_list}"

    def add_items(self, item: Furniture):
        """
        item: Furniture
        通过冒号:对象类型,加注解
        加上冒号后编写时可以联想
        """
        if (item.area > self.free_area):
            print("房子没空间了，放家具失败")
        else:
            self.free_area -= item.area
            self.items_list.append(item.name)


if __name__ == '__main__':
    bed = Furniture('席梦思', 4)
    chest = Furniture("衣柜", 2)
    table = Furniture("餐桌", 1.5)
    print(bed)
    print(chest)
    print(table)

    house = House("三室一厅", 110)
    print(house)
    house.add_items(bed)
    print(house)
    house.add_items(chest)
    print(house)
    house.add_items(table)
    print(house)
